package javolution.lang;

import java.util.Map;
import javolution.Javolution;
import javolution.context.LogContext;
import javolution.context.SecurityContext;
import javolution.text.Text;
import javolution.text.TextFormat;

/* loaded from: classes2.dex */
public class Configurable<T> {
    static final Logic LOGIC = new Logic() { // from class: javolution.lang.Configurable.1
    };
    private T _value;

    /* loaded from: classes2.dex */
    public static abstract class Logic {
        protected final <T> void configure(Configurable<T> configurable, T t) {
            if (!SecurityContext.getCurrent().isModifiable(configurable)) {
                throw new SecurityException("Configurable modification disallowed by SecurityContext");
            }
            Object obj = ((Configurable) configurable)._value;
            ((Configurable) configurable)._value = t;
            boolean z = true;
            if (t != null ? t.equals(obj) : obj == null) {
                z = false;
            }
            if (z) {
                configurable.notifyChange();
            }
        }
    }

    public Configurable(T t) {
        this._value = t;
    }

    public static void read(Map map) {
        Logic logic;
        for (Map.Entry entry : map.entrySet()) {
            String valueOf = String.valueOf(entry.getKey());
            Object value = entry.getValue();
            try {
                int indexOf = valueOf.indexOf(35);
                if (indexOf >= 0) {
                    LogContext.info("Configure " + valueOf + " to " + value);
                    String substring = valueOf.substring(0, indexOf);
                    Configurable<T> configurable = (Configurable) Reflection.getClass(substring).getDeclaredField(valueOf.substring(indexOf + 1)).get(null);
                    T t = configurable.get();
                    if (t != null && (value instanceof String)) {
                        String str = (String) value;
                        if (t instanceof String) {
                            logic = LOGIC;
                        } else {
                            TextFormat textFormat = TextFormat.getInstance(t.getClass());
                            if (textFormat != null) {
                                Logic logic2 = LOGIC;
                                value = textFormat.parse(Javolution.j2meToCharSeq(str));
                                logic = logic2;
                            } else {
                                LogContext.warning(Text.valueOf((Object) ("No text format found for type " + t.getClass() + " (" + valueOf + "), please register the text format using TextFormat.setInstance(Class, TextFormat) static method")));
                            }
                        }
                        logic.configure(configurable, value);
                    }
                    logic = LOGIC;
                    logic.configure(configurable, value);
                }
            } catch (Exception e) {
                LogContext.warning(Text.valueOf((Object) ("Cannot set property " + valueOf + "(" + e.toString() + ")")));
            }
        }
    }

    public final T get() {
        return this._value;
    }

    protected void notifyChange() {
    }

    public String toString() {
        return String.valueOf(this._value);
    }
}
